$(function(){
   var token=sessionStorage.getItem("token");
   var url="http://www.rice.com/app/api/h5_access";
})
    //上传身份
    function imgsc(obj){
        var fileType=$(obj).attr("id");
         layer.open({
            type: 1,
            offset: 'b' ,
            content: '<div style="width:200px;height:120px;"> <div id="clipArea" style="display:none;"></div> <input type="file" id="file" accept="image/*"  capture="camera"><button id="clipBtn" style="background:#007ebb;color:#fff;width:80%;height:35px;line-height:35px;border:0;">上传</button><div id="view" style="display:none;"></div></div>',
            btn: '关闭全部',
            btnAlign: 'c',
            shade: 1 ,
            yes: function(){
              layer.closeAll();
            }
          });       
            var clipArea = new bjj.PhotoClip("#clipArea", {
                size: [260, 260],
                outputSize: [640, 640],
                file: "#file",
                view: "#view",
                ok: "#clipBtn",
                loadStart: function(d) {
//                        console.log("照片读取中");
                },
                loadComplete: function(t) {
//                        console.log("照片读取完成");
                },
                clipFinish: function(dataURL) {
//                        console.log(dataURL);
                        var token=sessionStorage.getItem("token");
                       var dat=strToBinary(dataURL);
                       //转16进制
                       function strToBinary(str){
                            var result = [];
                            var list = str.split("");
                            for(var i=0;i<list.length;i++){
                                if(i != 0){
                                    result.push(" ");
                                }
                                var item = list[i];
                                var binaryStr = item.charCodeAt().toString(16);
                                result.push(binaryStr);
                            }   
                            return result.join("");
                        }
//                        document.write(dat);
//                        document.write(dat);
//                        var d=binaryToStr(dat);
////                            十六进制转字符串
//                            function binaryToStr(str){
//                                var result = [];
//                                var list = str.split(" ");
//                                for(var i=0;i<list.length;i++){
//                                     var item = list[i];
//                                     var asciiCode = parseInt(item,16);
//                                     var charValue = String.fromCharCode(asciiCode);
//                                     result.push(charValue);
//                                }
//                                return result.join("");
//                            }     
                        var method="img_upload";
                        var suffix="png";
                        var d={};
                        d.method=method;
                        d.token=token;
                        d.content=dat;
                        d.suffix=suffix;
                        d.fileType=fileType;
                        $.ajax({
                            type:"post",
                            url:"http://www.rice.com/app/api/h5_access",
                            data:d,
                            dataType:"json",
                            success:function(result){
                                if(result.status=="1"){
                                   var data= result.data;
                                   $("#"+fileType).attr("src",data.img_url);
                                }else if(result.status=="2"){
                                    alert(result.message);
                                    location.href="login.html";
                                }else{
                                    alert(result.message);
                                }
                                
                            }
                        })
                }
        });
    }
    $("#sftj").click(function(){
        var method="img_comfirm";
        var token=sessionStorage.getItem("token");
        var d={};
        d.method=method;
        d.token=token;
        $.ajax({
            type:"post",
            url:"http://www.rice.com/app/api/h5_access",
            data:d,
            dataType:"json",
            success:function(result){
                 if(result.status=="1"){
                     alert(result.message);
                     location.href="Rname.html"
                 }else if(result.status=="2"){
                    alert(result.message);
                    location.href="login.html";
                }else{
                    alert(result.message);
                }
            }
        })
    })
